﻿<template>
  <a-modal title="编辑运营日报" :width="1200" :visible="visible" :confirmLoading="confirmLoading" @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item v-show="false"  label="上级ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入上级ID" disabled v-decorator="['parentId']" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item v-show="false" label="上级编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入上级编码" disabled v-decorator="['parentDataCode']" />
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item v-show="false" label="编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入编码" disabled v-decorator="['dataCode']" />
        </a-form-item>

        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="数据大类"  :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入上级数据名称" disabled v-decorator="['parentDataName']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="数据名称"  :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入数据名称" disabled v-decorator="['dataName']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="机构名称"  :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入机构名称" disabled v-decorator="['hospitalName']" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="挂号数量" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入" v-decorator="['dayNum']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="收入金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入收入金额" v-decorator="['dataAmount']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="累计挂号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入当月累计数量" v-decorator="['monthNum']" />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="累计收入" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入当月累计金额" v-decorator="['monthAmount']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="充值金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入充值金额" v-decorator="['rechargeAmount']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="续费金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入续费金额" v-decorator="['reNewAmount']" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="退费金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入退费金额" v-decorator="['refundAmount']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="合计金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入合计金额" v-decorator="['totalAmount']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="日均数量" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入日均数量" v-decorator="['avgDayNum']" />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="日均金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入日均金额" v-decorator="['avgDayAmount']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="出院人数" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输出院人数" v-decorator="['field01']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="当月累计出院人数" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输当月累计出院人数" v-decorator="['field02']" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item label="新建卡" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输新建会员卡数" v-decorator="['field03']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item v-show="false" label="医院ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入医院ID" v-decorator="['hospitalId']" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item v-show="false" label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
              <a-input placeholder="请输入备注" v-decorator="['remark']" />
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item v-show="false" label="预留4" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留4" v-decorator="['field04']" />
        </a-form-item>
        <a-form-item v-show="false" label="预留5" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留5" v-decorator="['field05']" />
        </a-form-item>
        <a-form-item v-show="false" label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入状态" v-decorator="['status']" />
        </a-form-item>
        <a-form-item v-show="false" label="报表类型" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入报表类型" v-decorator="['type']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import {
  DayReportEdit
} from '@/api/modular/main/DayReportManage'
export default {
  data() {
    return {
      labelCol: {
        xs: { span: 12 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 12 },
        sm: { span: 15 }
      },
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this)
    }
  },
  methods: {
    // 初始化方法
    edit(record) {
      this.visible = true
      setTimeout(() => {
        this.form.setFieldsValue(
          {
            id: record.id,
            parentId: record.parentId,
            parentDataCode: record.parentDataCode,
            parentDataName: record.parentDataName,
            dataCode: record.dataCode,
            dataName: record.dataName,
            dayNum: record.dayNum,
            dataAmount: record.dataAmount,
            monthNum: record.monthNum,
            monthAmount: record.monthAmount,
            rechargeAmount: record.rechargeAmount,
            reNewAmount: record.reNewAmount,
            refundAmount: record.refundAmount,
            totalAmount: record.totalAmount,
            avgDayNum: record.avgDayNum,
            avgDayAmount: record.avgDayAmount,
            hospitalId: record.hospitalId,
            hospitalName: record.hospitalName,
            remark: record.remark,
            field01: record.field01,
            field02: record.field02,
            field03: record.field03,
            field04: record.field04,
            field05: record.field05,
            status: record.status,
            type: record.type
          }
        )
      }, 100)
    },
    handleSubmit() {
      const { form: { validateFields } } = this
      this.confirmLoading = true
      validateFields((errors, values) => {
        if (!errors) {
          for (const key in values) {
            if (typeof (values[key]) === 'object') {
              values[key] = JSON.stringify(values[key])
            }
          }
          DayReportEdit(values).then((res) => {
            if (res.success) {
              this.$message.success('编辑成功')
              this.confirmLoading = false
              this.$emit('ok', values)
              this.handleCancel()
            } else {
              this.$message.error('编辑失败：' + JSON.stringify(res.message))
            }
          }).finally((res) => {
            this.confirmLoading = false
          })
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel() {
      this.form.resetFields()
      this.visible = false
    }
  }
}
</script>
